<?php
	//danh sach danh chi tiet hoa don
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Untitled Document</title>
</head>

<body>
<?php
	function tinhtong()
	{
		$id=$_GET["id"];
		$result=mysql_query("SELECT * FROM chitiethdon WHERE iddh='$id'");
		$tong=0;
		while($row=mysql_fetch_assoc($result))
		{
			$tong=$tong+$row["thanhtien"];//load thanh tien
		}
		mysql_free_result($result);
		return $tong;
	}
?>
<?php
	
		if(isset($_GET["id"]))
		{
			$id=$_GET["id"];
		//	include("../pager.php");
			$limit=5;//ta lay gioi han cho cac phan tu trong trang web
			$totalcsdl=0;//khá»� tao cho mot gia tri = 0 de ok
			$result=mysql_query("SELECT * FROM chitiethdon WHERE iddh='$id'");
			$totalcsdl=mysql_num_rows($result);
			$ten=mysql_fetch_assoc($result);
			//$page=new pager();
			if($totalcsdl!=0)
			{
				//$start=$page->csdlfirst($limit);
			//	$countpage=$page->countpage($limit,$totalcsdl);
				$result=mysql_query("SELECT * FROM chitiethdon WHERE iddh=$id ");//LIMIT $start,$limit",$db
				
				$result1=mysql_query("SELECT * FROM hoadon WHERE id=$id");
				$row1=mysql_fetch_assoc($result1);
				if(mysql_num_rows($result)!=0)
				{
					echo"<br><table align='center' width='100%' border='1' cellpadding='2' cellspacing='2' style='border-collapse:collapse'>";
					echo"<tr><td colspan='4' bgcolor='#999999' align='center' style='font-weight:bold'>CHI TIáº¾T HÃ“A Ä�Æ N</td></tr>";
					echo"<tr><td colspan='4' bgcolor align='left' style='font-weight:bold'>KHÃ�CH HÃ€NG: ". stripslashes($row1["tenkhachhang"])."</td></tr>";
					echo"<tr align='center' bgcolor='#FFE0C1'>";
					echo"<td>Sản phẩm</td>";
					echo"<td>Số Lượng Mua</td>";
					echo"<td>Đơn Giá</td>";
					echo"<td>Thành Tiền</td>";
					echo"</tr>";
					$tong=tinhtong();
					while($row=mysql_fetch_assoc($result))
					{	$iddh=$row["idsanpham"];
						$result123=mysql_query("SELECT * FROM sanpham WHERE masanpham='$iddh'");
						$row12=mysql_fetch_assoc($result123);
						$hinhanh=$row12["hinhanh"];
						$hinhanh="../images/sanpham/".$hinhanh;
						$hinh="<img src='$hinhanh' width='100' height='120'>";
						//$mahoa=$row["id_hoa"];
						$soluong=$row["soluong"];
						$dongia=$row["dongia"];
						$thanhtien=$row["thanhtien"];
						//$tong=$tong+$thanhtien;
						if($stt%2==0)
							echo "<tr align='center' bgcolor='#FFE0C1'>";
						else
							echo "<tr align='center'>";
						echo "<td>$hinh</td>";
						echo "<td>$soluong</td>";
						echo "<td>".number_format($dongia,0,".",",")." VNĐ</td>";
						echo"<td>".number_format($thanhtien,0,".",",")." VNĐ</td>";
						
						echo"</tr>";
						
					}
					
					echo"<tr><td colspan='7' align='left' style='font-weight:bold'>Tá»•ng Sá»‘ Tiá»�n: ".number_format($tong,0,".",",")." VNĐ</td></tr>";
				echo"</table>";
					
					echo"<p><a href='javascript:history.go(-1)'>QUAY LẠI TRANG DANH SÁCH HÓA ĐƠN</a></p>";
				}
			}
		}	
	
?>
</body>
</html>
